-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for iterating only loaded values #311
Conversation
Added new feature required by Stable Cadence. New functions and structs include: - Array.IterateLoadedValues() - ArrayLoadedValueIterator - OrderedMap.IterateLoadedValues() - MapLoadedValueIterator etc. They have same API as regular iterators except that they only return already loaded elements.
Codecov Report
@@ Coverage Diff @@
## main #311 +/- ##
==========================================
+ Coverage 64.55% 65.01% +0.45%
==========================================
Files 14 14
Lines 8019 8387 +368
==========================================
+ Hits 5177 5453 +276
- Misses 2164 2236 +72
- Partials 678 698 +20
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Previously, Array and OrderedMap iterator used BFS to find all loaded data slabs first and then iterated all loaded elements in those data slabs. For Array and OrderedMap that are very large (with many data slabs), the previous approach can be less efficient than necessary. This PR uses DFS and tracks parents (slab iterators) in LIFO stack. Iterator gets new data iterator from last parent in the stack. Parent's stack is reused and its length is maintained at max depth - 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great work!
Maybe Supun (once he's back), Ramtin (once he's back), and/or someone else from the execution team can have a look as well before we merge |
Co-authored-by: Bastian Müller <[email protected]>
@SupunS could you please also have a look here? |
I might need some context on this one.
|
@ramtinms Thanks for taking a look!
I think the plan is Cadence runtime. Bastian and Supun provided some context in reply to this comment on the issue.
I think internal cache is purged on commit but I'm not sure how often commit is called. Maybe @turbolent or @janezpodhostnik can provide more info about how often that happens. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding this!
As usual, I don't know much about the atree internals, so mostly reviewed the general Go code. Looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me,
I only recommend adding a small test that changes the map or array contents in the middle of an iteration. not sure this would happen ever but that's the only edge case that comes to my mind that didn't find it tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me. I was especially looking for any sources of non-determinism, and it looks all good 👍.
Added tests that remove slabs from storage during iteration over loaded values. The scenario tested shouldn't happen in practice but we want to test that it would be handled gracefully.
Closes #303
Description
Added new functions and structs for a special iterators required by Stable Cadence:
They have same API as regular iterators except that they only return already loaded elements.
main
branchFiles changed
in the Github PR explorer